package com.rundatop.core.aspect;

import java.util.Arrays;

import javax.servlet.http.HttpServletRequest;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import com.rundatop.core.util.HttpContextUtils;
import com.rundatop.core.util.IPUtil;

/**
 * 测试用的针对于controller的切面操作
 * 
 * ***/

@Aspect
@Component
public class IPLogAspect {
	
	private static final Logger logger = LoggerFactory.getLogger(IPLogAspect.class);

	
	@Pointcut("execution(* com.rundatop.qrcode.controller..*.*(..))")
	public void ipPointCut() {
		
	}
	
	@Before("ipPointCut()")
	public void  befor(JoinPoint point) throws Throwable {
		// 执行方法
		//啥么鬼
		setIp(point);
		
	}
	
	public void setIp(JoinPoint joinPoint) {
		// 获取request
		HttpServletRequest request = HttpContextUtils.getHttpServletRequest();
		logger.error("<=====================================================");
        logger.error("请求来源： =》" + request.getRemoteAddr());
        logger.error("请求IP：" + IPUtil.getIpAddr(request));
        logger.error("请求URL：" + request.getRequestURL().toString());
        logger.error("请求方式：" + request.getMethod());
        logger.error("响应方法：" + joinPoint.getSignature().getDeclaringTypeName() + "." + joinPoint.getSignature().getName());
        logger.error("请求参数：" + Arrays.toString(joinPoint.getArgs()));
        logger.error("=====================================================>");
	}
	
}
